<?PHP
  class MySQL extends DataBase{
    private $connection;
    private $queries = 0;

    public function Execute($sql){
      $this->queries++;
      $res = $this->connection->query(str_replace("{'dbprefix'}",$this->Prefix,$sql));
      echo $this->error($sql);
      return $res;
    } 
    
    public function GetTables(){
      $this->queries++;
      $res =  $this->connection->query("SHOW TABLES");
      while($row = $res->fetch_row()){
        $tables[] = $row[0];
      }
      sort($tables);
      return $tables;
    }
      
    public function GetColumns($table){
      $this->queries++;
      $mysqlres = $this->Execute("SHOW COLUMNS FROM ".$table);
      while($row = $mysqlres->fetch_object()){
        $res[] = $row;
      }
      return $res;
    }
      
    public function ReadField($sql){
      $this->queries++;
      $res = $this->Execute($sql);
      $row = $res->fetch_row();
      return $row[0];
    }
      
    public function ReadRow($sql,$allowTranslate = true){
      $this->queries++;
      $res = $this->Execute($sql);
      $res = $res->fetch_object();
      if($allowTranslate){
        $res = $GLOBALS['language']->replaceLanguageTokensByObject($res);
      }
      return $res;
    }
      
    public function ReadRows($sql){
      $this->queries++;
      $res = array();
      $mysqlRes = $this->Execute($sql);
      while($row = $mysqlRes->fetch_object()){
        $row = $GLOBALS['language']->replaceLanguageTokensByObject($row);
        $res[] = $row;
      }
      return $res;
    }
    
    public function InsertID(){
      return $this->connection->insert_id;
    }
    
    public function EscapeString($text){
      return $this->connection->real_escape_string($text);
    }
      
    public function Connect(){
      $this->connection = new mysqli($this->Host,$this->User,$this->Password,$this->Name);
    }
      
    public function Disconnect(){
      $this->connection->close();
    }

    public function countQueries(){
      return $this->queries;
    }

	public function error($sql){
      $res = $this->connection->error;
      if($res){
        $res = "<strong>MySQL-Error:</strong> ".htmlentities($sql)."<br />".$res."<br /><br />";
      }
	  return $res;
	}
  }
?>